package neu.edu.vn.appmusic.ui;

import java.io.IOException;

import neu.edu.vn.appmusic.R;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ActivityPlayMusic extends Activity{
	public MediaPlayer mediaPlayer;
	String url;
	Button buttonPlay;
	Button buttonStop;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_demo_play_music);
		
		mediaPlayer = new MediaPlayer();
		url = "http://mp3.zing.vn/html5/song/ZmxGykGadNgmaxDytFmLn";
//		http://mp3.zing.vn/html5/song/knJGTLGNAcNDSpJTTvGkm
//		url = "http://realaudio.rferl.org/voa/VIET/2014/05/26/ea03f8b6-f10e-4e6e-abcb-3050de188b47.mp3";
		mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
		
		try {
			mediaPlayer.setDataSource(url);
		} catch (IllegalArgumentException | SecurityException
				| IllegalStateException | IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		
		try {
			mediaPlayer.prepare();
		} catch (IllegalStateException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		buttonPlay = (Button) findViewById(R.id.play);
		buttonStop = (Button) findViewById(R.id.stop);
		
		buttonPlay.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mediaPlayer.start();
			}
		});
		
		buttonStop.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mediaPlayer.pause();
			}
		});
	}

	
	

}
